package com.xcity;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import naga.x.util.IOUtils;

public class WindowsShutdown {

	public static void listen() {
		if (System.getProperty("os.name").toLowerCase().contains("windows")) {
			new Thread() {
				@Override
				public void run() {
					BufferedReader reader = null;
					try {
						reader = new BufferedReader(new InputStreamReader(System.in));
						while (true) {
							String cmd = reader.readLine();
							if ("exit".equals(cmd)) {
								System.exit(0);
							}
							try {
								Thread.sleep(10);
							} catch (InterruptedException e) {}
						}
					} catch (Exception e) {
						e.printStackTrace();
					} finally {
						IOUtils.closeQuietly(reader);
					}
				}
			}.start();
		}
	}
	
}
